package com.example.test.mapper;

import com.example.test.entity.Role;
import com.example.test.entity.UserRole;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface RoleMapper {

    @Select("select * from role")
    List<Role> findAll();

    @Select({
            "<script>",
            "select * from role where id in ",
            "<foreach collection='roleIds' item='id' index='index' open='(' separator=',' close=')'>",
            "#{id}",
            "</foreach>",
            "</script>"
    })
    List<Role> findAllByRoleId(@Param("roleIds") List<Integer> roleIds);

    //新增数据
    @Insert("insert into role(name) values (#{name})")
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    public int save(Role role);

    //删除数据
    @Delete("delete from role where id=#{id}")
    public int delete(int id);

    //根据id查找
    @Select("select * from role where id=#{id}")
    public Role get(int user);

    //更新数据
    @Update("update role set name=#{name} where id=#{id} ")
    public int update(Role role);

    public List<Role> findRoleByUserId();

}